/**
 * 
 */
package chatsystem;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * @author Thibaut POUZET
 *
 */

public class Message implements Serializable {

	/**
	 * @param args
	 */
	private Contact source;
	
	public Message(Contact source) {
		this.source = source;
		
	}
	
	public static byte[] toByteArray (Message m) throws Exception {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ObjectOutputStream oo = new ObjectOutputStream(os);
        oo.writeObject(m);
        oo.flush();
        oo.close();
        return os.toByteArray();
    }
	
	public static Message getMessage (byte[] data, int offset, int length) throws Exception {
        ByteArrayInputStream is = new ByteArrayInputStream(data,offset,length);
        ObjectInputStream oi = new ObjectInputStream (is);
        Message m = (Message) oi.readObject();
        oi.close();
        is.close();
        return m;
    }
	
	public Contact getSource() {
		return this.source;
	}
	
	public void setSource(Contact val) {
		this.source = val;
	}
	
	public String toString() {

		return source.toString();
		
	}
	
	
	public static void main(String[] args) {


	}

}
